﻿using System;
using Kiva7.Utilities;
using Kiva7.DataResponse;
using Kiva7.DataClasses;

namespace Kiva7.DataRequests
{
    public class LenderRequest : DataRequest<LendersResponse, Lender>
    {
        public LenderRequest()
            : base(true, true)
        {
        }

        public Uri BuildUri(string lenderId)
        {
            if (lenderId == null)
                return null;

            UrlCreator url = new UrlCreator(string.Format(BaseUrl + "lenders/{0}.xml", lenderId));

            url.Add("app_id", KivaAppId);

            return url.ToUri();
        }

        public void GetLender(string lenderId)
        {
            base.LoadResponse(BuildUri(lenderId));
        }


        public override LendersResponse CreateDefault()
        {
            LendersResponse lendersResponse = new LendersResponse();

            lendersResponse.Lenders = new Lenders();

            lendersResponse.Lenders.LenderItems.Add(
                new Lender()
                { 
                    Name = "Anonymous"
                });

            return lendersResponse;
        }
    }
}
